<?php

namespace App\Http\Controllers\Api\V5;

use App\Common\ApiData;
use App\Models\V1\CloMemberInfo;
use App\Models\V1\LearningOfficerMatter;
use App\Models\V1\LessonCenterNotice;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LessonsCenterController extends BaseController
{
    protected $clo;
    protected $apiData;

    public function __construct(CloMemberInfo $clo, ApiData $apiData)
    {
        $this->clo = $clo;
        $this->apiData = $apiData;
    }

    /**
     * 获取学习官中心的首页的信息
     * @param LessonCenterNotice $lessonCenterNotice
     * @param LearningOfficerMatter $learningOfficerMatter
     * @return \Illuminate\Http\JsonResponse
     */
    public function info(LessonCenterNotice $lessonCenterNotice, LearningOfficerMatter $learningOfficerMatter)
    {
        $noticeData = $lessonCenterNotice->get_all()->toArray();
        foreach ($noticeData as $k => $v) {
            if ($v->type == 2) ;
            $v->link = ($v->type == 2) ? url('/api/v4/share', ['id' => $v->notice_id]) : null;
        }
        $article = $learningOfficerMatter->get_article_data()->toArray();

        $lessonsCenterData = array_merge(['notice' => $noticeData], ['article' => $article]);

        return $this->apiData->set_data('lessonsCenterData', $lessonsCenterData)->send(200, '成功');
    }
}
